package edu.hcmus.sow.domain;

import java.io.Serializable;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlType;

import org.codehaus.jackson.annotate.JsonIgnore;

/**
 */

@Entity
@NamedQueries({
		@NamedQuery(name = "findAllGroupAuthoritiess", query = "select myGroupAuthorities from GroupAuthorities myGroupAuthorities"),
		@NamedQuery(name = "findGroupAuthoritiesById", query = "select myGroupAuthorities from GroupAuthorities myGroupAuthorities where myGroupAuthorities.id = ?1"),
		@NamedQuery(name = "findGroupAuthoritiesByPrimaryKey", query = "select myGroupAuthorities from GroupAuthorities myGroupAuthorities where myGroupAuthorities.id = ?1") })
@Table(catalog = "sow", name = "group_authorities")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace = "SharedOnlineWorkspace/edu/hcmus/sow/domain", name = "GroupAuthorities")
public class GroupAuthorities implements Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 */

	@Column(name = "ID", nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	@XmlElement
	Integer id;

	/**
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "GROUP_ID", referencedColumnName = "ID", nullable = false) })
	@XmlTransient
	Group group;
	/**
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "AUTHORITIES_ID", referencedColumnName = "ID", nullable = false) })
	@XmlTransient
	Authorities authorities;

	/**
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 */
	public Integer getId() {
		return this.id;
	}

	/**
	 */
	public void setGroup(Group group) {
		this.group = group;
	}

	/**
	 */
	@JsonIgnore
	public Group getGroup() {
		return group;
	}

	/**
	 */
	public void setAuthorities(Authorities authorities) {
		this.authorities = authorities;
	}

	/**
	 */
	@JsonIgnore
	public Authorities getAuthorities() {
		return authorities;
	}

	/**
	 */
	public GroupAuthorities() {
	}

	/**
	 * Copies the contents of the specified bean into this bean.
	 *
	 */
	public void copy(GroupAuthorities that) {
		setId(that.getId());
		setGroup(that.getGroup());
		setAuthorities(that.getAuthorities());
	}

	/**
	 * Returns a textual representation of a bean.
	 *
	 */
	public String toString() {

		StringBuilder buffer = new StringBuilder();

		buffer.append("id=[").append(id).append("] ");

		return buffer.toString();
	}

	/**
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = (int) (prime * result + ((id == null) ? 0 : id.hashCode()));
		return result;
	}

	/**
	 */
	public boolean equals(Object obj) {
		if (obj == this)
			return true;
		if (!(obj instanceof GroupAuthorities))
			return false;
		GroupAuthorities equalCheck = (GroupAuthorities) obj;
		if ((id == null && equalCheck.id != null) || (id != null && equalCheck.id == null))
			return false;
		if (id != null && !id.equals(equalCheck.id))
			return false;
		return true;
	}
}
